
package ch.raph.test.mvc.model;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractModel<T> implements Observable<T>
    {
    
    /*------------------------------------------------------------------
    attributs private
    ------------------------------------------------------------------*/
    protected T m_data;
    private List<Observer<T>> m_listObserver = new ArrayList<Observer<T>>();

    /*------------------------------------------------------------------
    methods public
    ------------------------------------------------------------------*/
    public abstract void reset();
    
    public abstract T getData();
    
    public abstract void setData(T data);
    
    @Override
    public void addObserver(Observer<T> obs)
        {
        m_listObserver.add(obs);
        }
    
    @Override
    public void removeObserver()
        {
        m_listObserver.clear();
        }
    
    @Override
    public void notifyObserver(T before, T after)
        {
        for(Observer<T> obs:m_listObserver)
            {
            obs.update(before, after);
            }
        
        }
    }
